/**
 * 
 */
package com.qdairlines.controller.dict;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qdairlines.common.Select2Util;
import com.qdairlines.constant.BaseConsts;
import com.qdairlines.entity.user.User;
import com.qdairlines.service.user.UserService;

/**
 * @author pangyannan
 * @date 2017年4月11日
 * @company QingDao Airlines
 * @description 主要用于返回select2数据
 */
@Controller
@RequestMapping("select2")
public class Select2Controller {

	@Autowired
	private UserService userService;

	/**
	 * 
	 * @param queryKey
	 *            用户输入框查询参数
	 * @param viewKey
	 *            数据回显时传入的id值
	 * @return
	 */
	@RequestMapping(value = "getUser", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String getUser(String queryKey, String viewKey) {
		List<User> list = new ArrayList<>();
		if (queryKey != null) {
			if (BaseConsts.SPACE.equals(queryKey)) {
				queryKey = null;
			}
			User user = new User();
			list = userService.listData(user);
		} else if (viewKey != null) {
			User user = new User();
			list = userService.listData(user);
		}
		return Select2Util.toJosn(list, "workcode", "userName");
	}

}
